
using System;
using System.Collections.Generic;
using System.Text;

using Derm.Render;
using Derm.Scene;

namespace Derm.Examples
{
	[RenderObjectProgram("StandardShader", "DS_COLOR_PER_VERTEX")]
	class UnitCube : SceneObject
	{
		#region Constructors

		public UnitCube()
		{
			VertexArrayObject vao = new VertexArrayObject();
			ArrayBufferObject<VertexData> vertexData = new ArrayBufferObject<VertexData>(BufferObject.Hint.StaticCpuDraw);
			ArrayBufferObject<Vertex3f> vertices = new ArrayBufferObject<Vertex3f>(BufferObject.Hint.StaticCpuDraw);
			ArrayBufferObject<ColorRGBAF> colors = new ArrayBufferObject<ColorRGBAF>(BufferObject.Hint.StaticCpuDraw);

			vertices.Define(sCubeVertices);
			//vao.SetArray("ds_VertexPosition", "StandardVertexShaderInputs", vertices);

			colors.Define(sCubeColors);
			//vao.SetArray("ds_VertexColor", "StandardVertexShaderInputs", colors);

			vao.SetArray("ds_VertexPosition", "StandardVertexShaderInputs", vertices);
			vao.SetArray("ds_VertexColor", "StandardVertexShaderInputs", colors);
			vao.SetElementArray(Primitive.Triangle);
			
			VertexArrays.AddVertexArray(vao);
		}

		private struct VertexData
		{
			public VertexData(Vertex3f position, ColorRGBAF color)
			{
				VertexPosition = position;
				VertexColor = color;
			}

			public Vertex3f VertexPosition;

			public ColorRGBAF VertexColor;
		}

		private static readonly VertexData[] sCubeVertexData = new VertexData[] {
			new VertexData(new Vertex3f(-1.0f, -1.0f, +1.0f), new ColorRGBAF(0.0f, 0.0f, 1.0f)),	// Face +Z
			new VertexData(new Vertex3f(+1.0f, -1.0f, +1.0f), new ColorRGBAF(0.0f, 0.0f, 1.0f)),
			new VertexData(new Vertex3f(+1.0f, +1.0f, +1.0f), new ColorRGBAF(0.0f, 0.0f, 1.0f)),
			new VertexData(new Vertex3f(-1.0f, -1.0f, +1.0f), new ColorRGBAF(0.0f, 0.0f, 1.0f)),
			new VertexData(new Vertex3f(+1.0f, +1.0f, +1.0f), new ColorRGBAF(0.0f, 0.0f, 1.0f)),
			new VertexData(new Vertex3f(-1.0f, +1.0f, +1.0f), new ColorRGBAF(0.0f, 0.0f, 1.0f)),

			new VertexData(new Vertex3f(+1.0f, -1.0f, +1.0f), new ColorRGBAF(0.0f, 0.0f, 1.0f)),	// Face +X
			new VertexData(new Vertex3f(+1.0f, -1.0f, -1.0f), new ColorRGBAF(0.0f, 0.0f, 1.0f)),
			new VertexData(new Vertex3f(+1.0f, +1.0f, -1.0f), new ColorRGBAF(0.0f, 0.0f, 1.0f)),
			new VertexData(new Vertex3f(+1.0f, -1.0f, +1.0f), new ColorRGBAF(0.0f, 0.0f, 1.0f)),
			new VertexData(new Vertex3f(+1.0f, +1.0f, -1.0f), new ColorRGBAF(0.0f, 0.0f, 1.0f)),
			new VertexData(new Vertex3f(+1.0f, +1.0f, +1.0f), new ColorRGBAF(0.0f, 0.0f, 1.0f)),
		};


		/// <summary>
		/// Cube vertices position.
		/// </summary>
		private static readonly Vertex3f[] sCubeVertices = new Vertex3f[] {
			new Vertex3f(-1.0f, -1.0f, +1.0f), new Vertex3f(+1.0f, -1.0f, +1.0f), new Vertex3f(+1.0f, +1.0f, +1.0f),	// Face +Z
			new Vertex3f(-1.0f, -1.0f, +1.0f), new Vertex3f(+1.0f, +1.0f, +1.0f), new Vertex3f(-1.0f, +1.0f, +1.0f),	// Face +Z
			new Vertex3f(+1.0f, -1.0f, +1.0f), new Vertex3f(+1.0f, -1.0f, -1.0f), new Vertex3f(+1.0f, +1.0f, -1.0f),	// Face +X
			new Vertex3f(+1.0f, -1.0f, +1.0f), new Vertex3f(+1.0f, +1.0f, -1.0f), new Vertex3f(+1.0f, +1.0f, +1.0f),	// Face +X
			new Vertex3f(+1.0f, -1.0f, -1.0f), new Vertex3f(-1.0f, -1.0f, -1.0f), new Vertex3f(-1.0f, +1.0f, -1.0f),	// Face -Z
			new Vertex3f(+1.0f, -1.0f, -1.0f), new Vertex3f(-1.0f, +1.0f, -1.0f), new Vertex3f(+1.0f, +1.0f, -1.0f),	// Face -Z
			new Vertex3f(-1.0f, -1.0f, -1.0f), new Vertex3f(-1.0f, -1.0f, +1.0f), new Vertex3f(-1.0f, +1.0f, +1.0f),	// Face -X
			new Vertex3f(-1.0f, -1.0f, -1.0f), new Vertex3f(-1.0f, +1.0f, +1.0f), new Vertex3f(-1.0f, +1.0f, -1.0f),	// Face -X
			new Vertex3f(+1.0f, +1.0f, +1.0f), new Vertex3f(+1.0f, +1.0f, -1.0f), new Vertex3f(-1.0f, +1.0f, -1.0f),	// Face +Y
			new Vertex3f(+1.0f, +1.0f, +1.0f), new Vertex3f(-1.0f, +1.0f, -1.0f), new Vertex3f(-1.0f, +1.0f, +1.0f),	// Face +Y
			new Vertex3f(-1.0f, -1.0f, -1.0f), new Vertex3f(+1.0f, -1.0f, -1.0f), new Vertex3f(+1.0f, -1.0f, +1.0f),	// Face -Y
			new Vertex3f(-1.0f, -1.0f, -1.0f), new Vertex3f(+1.0f, -1.0f, +1.0f), new Vertex3f(-1.0f, -1.0f, +1.0f)		// Face -Y
		};

		/// <summary>
		/// Sube vertices color.
		/// </summary>
		private static readonly ColorRGBAF[] sCubeColors = new ColorRGBAF[] {
			new ColorRGBAF(0.0f, 0.0f, 1.0f), new ColorRGBAF(0.0f, 0.0f, 1.0f), new ColorRGBAF(0.0f, 0.0f, 1.0f),		// Face +Z
			new ColorRGBAF(0.0f, 0.0f, 1.0f), new ColorRGBAF(0.0f, 0.0f, 1.0f), new ColorRGBAF(0.0f, 0.0f, 1.0f),		// Face +Z
			new ColorRGBAF(1.0f, 0.0f, 0.0f), new ColorRGBAF(1.0f, 0.0f, 0.0f), new ColorRGBAF(1.0f, 0.0f, 0.0f),		// Face +X
			new ColorRGBAF(1.0f, 0.0f, 0.0f), new ColorRGBAF(1.0f, 0.0f, 0.0f), new ColorRGBAF(1.0f, 0.0f, 0.0f),		// Face +X
			new ColorRGBAF(0.0f, 0.0f, 1.0f), new ColorRGBAF(0.0f, 0.0f, 1.0f), new ColorRGBAF(0.0f, 0.0f, 1.0f),		// Face -Z
			new ColorRGBAF(0.0f, 0.0f, 1.0f), new ColorRGBAF(0.0f, 0.0f, 1.0f), new ColorRGBAF(0.0f, 0.0f, 1.0f),		// Face -Z
			new ColorRGBAF(1.0f, 0.0f, 0.0f), new ColorRGBAF(1.0f, 0.0f, 0.0f), new ColorRGBAF(1.0f, 0.0f, 0.0f),		// Face -X
			new ColorRGBAF(1.0f, 0.0f, 0.0f), new ColorRGBAF(1.0f, 0.0f, 0.0f), new ColorRGBAF(1.0f, 0.0f, 0.0f),		// Face -X
			new ColorRGBAF(0.0f, 1.0f, 0.0f), new ColorRGBAF(0.0f, 1.0f, 0.0f), new ColorRGBAF(0.0f, 1.0f, 0.0f),		// Face +Y
			new ColorRGBAF(0.0f, 1.0f, 0.0f), new ColorRGBAF(0.0f, 1.0f, 0.0f), new ColorRGBAF(0.0f, 1.0f, 0.0f),		// Face +Y
			new ColorRGBAF(0.0f, 1.0f, 0.0f), new ColorRGBAF(0.0f, 1.0f, 0.0f), new ColorRGBAF(0.0f, 1.0f, 0.0f),		// Face -Y
			new ColorRGBAF(0.0f, 1.0f, 0.0f), new ColorRGBAF(0.0f, 1.0f, 0.0f), new ColorRGBAF(0.0f, 1.0f, 0.0f)		// Face -Y
		};

		#endregion
	}
}
